﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 基础地块类，其他类型的地块继承该地块
/// </summary>
public class BasicBlock : MonoBehaviour
{

    public bool isBeforePlayer = false;

    public List<GameObject> players;
    public bool isPlayerIn = false;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Coin")
        {
            isPlayerIn = true;
            players.Add(collision.gameObject);
            BlockIn(collision.gameObject);
        }
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Coin")
        {
            isPlayerIn = true;
            BlockStay(collision.gameObject);
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Coin")
        {
            isPlayerIn = false;
            players.Remove(collision.gameObject);
            BlockOut(collision.gameObject);
        }
    }


    //子类重写该方法以实现各种地块效果
    public virtual void BlockStay(GameObject player)
    {

    }
    public virtual void BlockIn(GameObject player)
    {

    }
    public virtual void BlockOut(GameObject player)
    {

    }


    // Start is called before the first frame update
    void Start()
    {
        // players = new List<GameObject>();
        // if (isBeforePlayer)
        // {
        //     transform.Translate(new Vector3(transform.position.x, transform.position.y, -100));
        // }
        // else
        // {
        //     transform.Translate(new Vector3(transform.position.x, transform.position.y, 40));
        // }
    }

    

    // Update is called once per frame
    void Update()
    {
    }
}
